package com.jeebey.mybatis.query;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author J4T Dubbo 不支持 Pagination对象 故封装了 PagingResult
 * @param <T>
 */
@SuppressWarnings("serial")
public class PagingResult<T> implements Serializable {

	/** 总记录数 */
	private long total;
	/** 当前页 */
	private int page;
	/** 每页记录数 */
	private int size;

	private List<T> items = new ArrayList<T>();

	public PagingResult() {

	}

	public PagingResult(Pagination<T> pagination) {
		this.page = pagination.getPage();
		this.size = pagination.getSize();
		this.total = pagination.getTotal();
		this.items.addAll(pagination.getItems());
	}

	public PagingResult(long total, int page, int size, List<T> items) {
		this.page = page;
		this.size = size;
		this.total = total;
		this.items.addAll(items);
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public List<T> getItems() {
		return items;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	/** 每页记录数 */
	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	/** 总页数 */
	public int getPages() {
		return (int) Math.ceil(this.total / (this.size * 1.0));
	}
}
